/******************************************************************************/
/*  Class USB                                                                 */
/*  PO: S. Maslyakov, rusoil.9@gmail.com                                      */
/*                                                                            */
/*  Revision:     1.5                                                         */
/*  Date:         2011/01/11 00:53:33                                         */
/******************************************************************************/


#ifndef __USB_H
#define __USB_H


#include "data_types.h"
#include "Usb\usb_def.h"
#include "Usb\usb_hw.h"
#include "Usb\usb_cdc.h"
#include "Usb\usb_descr.h"


//==============================================================================
//  Class USB
//==============================================================================
class USB
{
public:
  static void Init_Usb();
  static void UsbReset();
  static void InterruptHandlerUsb();
  static void UsbTxDataBulk(const uint8_t * const _pData, const uint32_t _len);
  static void HandlerEp0(const uint32_t _eDir, const uint8_t _epStatus);

private:
  static void DevReqHandler();
  static void CdcIfReqHandler();
  static void HandlerEp1(const uint32_t _eDir);
  static void HandlerEp2(const uint32_t eDir);
  static void WriteSieCmd(const uint32_t _cmd);
  static void WriteSieCmdData(const uint32_t _cmd, const uint32_t _data);
  static void UsbTxDataEp0(uint8_t * const _pData, const uint32_t _len);
  static void UsbTxDataEp1(const uint8_t _status);
  inline static void IfReqHandler() { m_tools.flgStall = TRUE_T; }
  inline static void EpReqHandler() { m_tools.flgStall = TRUE_T; }
  static uint8_t ReadSieData(const uint32_t _cmd);
  static uint32_t UsbReadEP(const uint32_t _eEpNum, uint8_t * _pData);
  static uint32_t UsbWriteEP(const uint32_t _eEpNum,
                             const uint8_t * _pData,
                             const uint32_t _dataLen);

  static __USB_RX_BUFF_TOOLS m_rxBuff;
  static __USB_TX_BUFF_TOOLS m_txBuff;
  static __USB_BULK_TX_BUFF_TOOLS m_bulkTxBuff;
  static __USB_TOOLS m_tools;
  static __USB_SETUP_PACKET m_setup;
  static __USB_SETUP_PACKET m_setupData;
  static __CDC_PORT_SETT m_cdcPortSett;
  static __CDC_PORT_STATE m_cdcPortState;
};
//==========================================================================
//==========================================================================


#endif